import { View, Navigator, Text } from '@tarojs/components'
import { useState } from 'react'
import { formatTime } from '../../utils'
import XLoadMore from '../../components/XLoadMore'
import { getUserVoteListPageApi } from '../../services/Vote'
import { AtFab } from 'taro-ui'
import Taro from '@tarojs/taro'
import './index.scss'

export default () => {
    let [voteList, setvoteList] = useState<any[]>([])
    function loadFinish(rows:any[]) {
        voteList.push(...rows)
        setvoteList([...voteList])
    }
    return <>
        <View className='vote-list'>
            {
                voteList.map(vote => <Navigator className='item' url={'/pages/vote/index?id=' + vote.id}>
                <View className='content'>{vote.content}</View>
                <View className='bar'>
                    <Text>{formatTime(vote.create_time)}</Text>
                    <Text className='m-l-10'>{vote.total_score}投票</Text>
                </View>
                <View className='blank'></View>
            </Navigator>)
            }
        </View>
        <View>
            <XLoadMore onClick={getUserVoteListPageApi} onFinish={loadFinish}></XLoadMore>
        </View>

        <View className='publish-btn'>
            <AtFab onClick={() => Taro.navigateTo({url : '/pages/publish/index'})}>发布</AtFab>
        </View>
    </>
}